package com.atm.atmsys.Mapper.AccountMapper;

import com.atm.atmsys.dto.*;
import com.atm.atmsys.entity.AccountInfo;
import com.github.pagehelper.Page;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface AccountMapper {


    //添加账户信息
    @Insert("insert into account_info (card_no,account_password,account_status,balance,account_time,identification)" +
            " values (#{cardNo},#{accountPassword},#{accountStatus},#{balance},#{accountTime},#{identification})")
    void addAccount(AccountInfo accountInfo);

    //ATM登录
    @Select("select * from account_info where card_no = #{cardNo} and account_password = #{accountPassword}")
    AccountInfo getByAccountCardNo(AccountInfo accountInfo);

    //获取所有卡号
    @Select("select card_no from account_info")
    List<String> getAllCardNO();

    //根据卡号删除账户信息
    @Delete("delete from account_info where card_no=#{cardno}")
    void deleteAccount(String cardno);

    //修改账户状态
    @Update("update account_info set account_status = #{accountStatus} where account_id = #{accountId}")
    void updateAccountStatus(AccountStatusDTO accountStatusDTO);


    //根据卡号获取余额
    @Select("select balance from account_info where card_no = #{cardNo}")
    double getBalanceByCardNO(String cardNo);

    //存款
    @Update("update account_info set balance = balance + #{money} where card_no = #{cardNo}")
    void saveMoney(SaveMoneyDTO saveMoneyDTO);

    //根据卡号获取账户状态
    @Select("select account_status from account_info where card_no = #{cardNo}")
    String getAccountStatusByCardNO(String cardNo);

    //取款
    @Update("update account_info set balance = balance - #{money} where card_no = #{cardNo}")
    void drawMoney(DrawMoneyDTO drawMoneyDTO);

    //根据卡号转移账户
    @Update("update account_info set identification =  #{identification} where card_no = #{cardNo}")
    void transfer(AccountTransDTO accountTransDTO);


    //根据身份证号获取卡号
    @Select("select card_no from account_info where identification = #{identification}")
    List<String> getCardNOByIdentification(String identification);

    //根据卡号判断账户是否存在
    @Select("select * from account_info where card_no = #{cardNo}")
    AccountInfo getAccountByCardNO(String cardNo);

    //分页查询账户信息
    Page<AccountInfo> pageQueryAccount(AccountPageDTO accountPageDTO);

    Page<AccountInfo> pageQueryUserAccount(YinLianAccountPageDTO yinLianAccountPageDTO);
}
